package com.api.user.controller;

import com.api.core.annotation.PowerEnable;
import com.api.core.response.Result;
import com.api.core.response.ResultGenerator;
import com.api.user.model.RankRapid;
import com.api.user.model.RankTournament;
import com.api.user.service.RankRapidService;
import com.api.user.service.RankTournamentService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@PowerEnable(name = "point交易明细",url = "/points/transaction")
@Api(value = "point交易明细", tags = {"point交易明细"})
@RestController
@RequestMapping("/rank")
public class RankController {

    @Resource
    private RankTournamentService rankTournamentService;
    @Resource
    private RankRapidService rankRapidService;

    @PostMapping(value="/rapid",name="竞猜榜")
    public Result rapid() {
        return ResultGenerator.genSuccessResult(rankRapidService.findAll());
    }

    @PostMapping(value="/tournament",name="赛事榜")
    public Result tournament() {
        List<RankTournament> ranks = rankTournamentService.findAll();
        Map<Integer,List<RankTournament>> res = ranks.stream().collect(Collectors.groupingBy(RankTournament::getType));
        return ResultGenerator.genSuccessResult(res);
    }


    @PostMapping(value="/rapid/update",name="更新竞猜榜")
    public Result rapidUpdate() {
        return rankRapidService.updateRanking();
    }


    @PostMapping(value="/tournament/update",name="赛事榜")
    public Result tournamentUpdate() {
        return  rankTournamentService.updateRanking();
    }
}
